package club.hicode.daydayup.threadpool;

import cn.hutool.core.thread.ThreadUtil;
import org.jboss.netty.util.internal.ExecutorUtil;
import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池学习
 *
 * @author Liu Chunfu
 * @date 2018-06-12 上午10:53
 **/
public class ThreadPoolTest {

    @Test
    public void testSingle() {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.execute(new Thread() {
            @Override
            public void run() {
                super.run();
            }
        });


        for (int i = 0; i < 3; i++) {
            executor.execute(() -> {
                System.out.println(Thread.currentThread().getId());
                throw new RuntimeException("123");
            });
        }

    }

    @Test
    public void testFix() {
        ExecutorService executor = Executors.newFixedThreadPool(5);
        executor.execute(() -> System.out.println(123));

    }

    @Test
    public void test1() {
        //cache 的 coresize 为0，但是有队列
        ExecutorService executorService = Executors.newCachedThreadPool();

        ExecutorService executorService1 = Executors.newFixedThreadPool(5);


    }
}
